home *** CD-ROM | disk | FTP | other *** search
/ Champak 119 / (Vol 119) Nov 09 2010.iso / TGKI-109 / Games / agent_platformer.swf / scripts / frame_7 / DoAction.as
Text File  |  2010-11-09  |  10KB  |  347 lines

  1. function feet_on_ladder()
  2. {
  3.    return _root.lad.hitTest(player._x,player._y + player._height / 2 - 1,true);
  4. }
  5. function level_under_my_feet()
  6. {
  7.    return _root.lev.hitTest(player._x,player._y + player._height / 2,true);
  8. }
  9. function ladder_under_my_feet()
  10. {
  11.    return _root.lad.hitTest(player._x,player._y + player._height / 2,true);
  12. }
  13. stop();
  14. score = 0;
  15. _root.attachMovie("jet_bar","jet_bar",_root.getNextHighestDepth(),{_x:95,_y:30});
  16. _root.attachMovie("player","player",_root.getNextHighestDepth(),{_x:40,_y:40});
  17. level1[0] = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
  18. level1[1] = new Array(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
  19. level1[2] = new Array(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
  20. level1[3] = new Array(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
  21. level1[4] = new Array(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,1);
  22. level1[5] = new Array(1,0,0,0,0,0,6,6,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1);
  23. level1[6] = new Array(1,0,0,0,0,0,1,1,1,4,0,0,1,1,0,0,0,2,0,0,0,0,0,0,1);
  24. level1[7] = new Array(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,1);
  25. level1[8] = new Array(1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,1);
  26. level1[9] = new Array(1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,2,0,0,0,0,0,0,1);
  27. level1[10] = new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,6,0,1);
  28. level1[11] = new Array(1,0,0,0,0,0,0,0,0,0,0,0,1,2,1,0,0,2,0,0,0,0,6,0,1);
  29. level1[12] = new Array(1,0,0,0,0,0,0,1,3,1,0,0,0,2,0,0,0,2,0,0,0,0,6,0,1);
  30. level1[13] = new Array(1,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,6,0,1);
  31. level1[14] = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,1,1,1,1,1,1);
  32. update();
  33. up = 1;
  34. lose_once = false;
  35. player.onEnterFrame = function()
  36. {
  37.    p.sound_btn.onRelease = function()
  38.    {
  39.       if(son_ == true and stimer > 5)
  40.       {
  41.          sound.removeMovieClip();
  42.          p.sound_btn.nextFrame();
  43.          stopAllSounds();
  44.          stimer = 0;
  45.          sup = true;
  46.          son_ = false;
  47.       }
  48.       if(son_ == false and stimer > 5)
  49.       {
  50.          attachMovie("sound","sound",_root.getNextHighestDepth());
  51.          p.sound_btn.prevFrame();
  52.          stimer = 0;
  53.          sup = true;
  54.          son_ = true;
  55.       }
  56.    };
  57.    if(timers <= 0 and lose_once == false)
  58.    {
  59.       if(mode_ != 0)
  60.       {
  61.          lose_once = true;
  62.          started_game = false;
  63.          attachMovie("l","l",_root.getNextHighestDepth(),{_x:250,_y:150});
  64.          l._alpha = 100;
  65.          l.onEnterFrame = function()
  66.          {
  67.             if(ldecay == true)
  68.             {
  69.                this._alpha -= 2;
  70.                if(this._alpha <= 0)
  71.                {
  72.                   removeMovieClip(this);
  73.                   gotoAndStop("menu");
  74.                }
  75.             }
  76.             this.menu_.onRelease = function()
  77.             {
  78.                ldecay = true;
  79.             };
  80.          };
  81.       }
  82.    }
  83.    if(started_game == true)
  84.    {
  85.       if(jet_bar.jet_bar_inside._width < 108)
  86.       {
  87.          jet_bar.jet_bar_inside._width += 0.1;
  88.       }
  89.       if(Key.isDown(80))
  90.       {
  91.          up = 0;
  92.          started_game = false;
  93.          pdecay = false;
  94.          decay2 = false;
  95.          attachMovie("p","p",_root.getNextHighestDepth(),{_x:250,_y:150});
  96.          p._alpha = 100;
  97.          p.onEnterFrame = function()
  98.          {
  99.             if(pdecay == true)
  100.             {
  101.                this._alpha -= 2;
  102.                if(this._alpha <= 0)
  103.                {
  104.                   up = 1;
  105.                   started_game = true;
  106.                   removeMovieClip(this);
  107.                }
  108.             }
  109.             if(decay2 == true)
  110.             {
  111.                this._alpha -= 2;
  112.                if(this._alpha <= 0)
  113.                {
  114.                   removeMovieClip(this);
  115.                   gotoAndStop("menu");
  116.                }
  117.             }
  118.             this.back.onRelease = function()
  119.             {
  120.                pdecay = true;
  121.             };
  122.             this.menu_.onRelease = function()
  123.             {
  124.                decay2 = true;
  125.             };
  126.          };
  127.       }
  128.       timers -= up;
  129.       show_score = "Coins : " + score;
  130.       if(Key.isDown(37) || Key.isDown(65))
  131.       {
  132.          if(climbing)
  133.          {
  134.             this.gotoAndStop(2);
  135.             xspeed = - climb_speed;
  136.          }
  137.          else if(walking_while_jumping or can_jump)
  138.          {
  139.             this.gotoAndStop(2);
  140.             this.player_inside.play();
  141.             xspeed = - walk_speed;
  142.          }
  143.       }
  144.       else if(this._currentframe == 2)
  145.       {
  146.          this.player_inside.gotoAndStop(1);
  147.       }
  148.       if(Key.isDown(39) || Key.isDown(68))
  149.       {
  150.          if(climbing)
  151.          {
  152.             this.gotoAndStop(1);
  153.             xspeed = climb_speed;
  154.          }
  155.          else if(walking_while_jumping or can_jump)
  156.          {
  157.             this.gotoAndStop(1);
  158.             this.player_inside.play();
  159.             xspeed = walk_speed;
  160.          }
  161.       }
  162.       else if(this._currentframe == 1)
  163.       {
  164.          this.player_inside.gotoAndStop(1);
  165.       }
  166.       if(!feet_on_ladder())
  167.       {
  168.          climbing = false;
  169.       }
  170.       if(using_jetpack == false)
  171.       {
  172.          this.pack.gotoAndStop(1);
  173.       }
  174.       if(Key.isDown(38) || Key.isDown(87))
  175.       {
  176.          if(has_jetpack == true)
  177.          {
  178.             if(feet_on_ladder() == false)
  179.             {
  180.                this.player_inside.gotoAndStop(1);
  181.                this.pack.gotoAndStop(2);
  182.                using_jetpack = true;
  183.                climbing = false;
  184.                jumping = true;
  185.                yspeed = - jet_speed;
  186.                jet_bar.jet_bar_inside._width--;
  187.             }
  188.          }
  189.          if(feet_on_ladder())
  190.          {
  191.             yspeed = - climb_speed;
  192.             using_jetpack = false;
  193.             climbing = true;
  194.             jumping = false;
  195.          }
  196.       }
  197.       else
  198.       {
  199.          using_jetpack = false;
  200.       }
  201.       if(jet_bar.jet_bar_inside._width <= 1)
  202.       {
  203.          using_jetpack = false;
  204.          has_jetpack = false;
  205.       }
  206.       else
  207.       {
  208.          has_jetpack = true;
  209.       }
  210.       if(Key.isDown(40) || Key.isDown(83))
  211.       {
  212.          if(feet_on_ladder() or ladder_under_my_feet())
  213.          {
  214.             yspeed = climb_speed;
  215.             climbing = true;
  216.             jumping = false;
  217.          }
  218.       }
  219.       if(Key.isDown(32) and can_jump and !jumping and !climbing)
  220.       {
  221.          yspeed -= jump_power;
  222.          jumping = true;
  223.       }
  224.       if(!climbing)
  225.       {
  226.          yspeed += gravity;
  227.       }
  228.       if(yspeed > max_yspeed)
  229.       {
  230.          yspeed = max_yspeed;
  231.       }
  232.       if(level_under_my_feet() and !jumping and !climbing)
  233.       {
  234.          yspeed = 0;
  235.       }
  236.       if(ladder_under_my_feet() and !jumping and !climbing)
  237.       {
  238.          yspeed = 0;
  239.       }
  240.       forecast_x = this._x + xspeed;
  241.       forecast_y = this._y + yspeed;
  242.       if(_root.exit_door.hitTest(forecast_x,forecast_y + this._height / 2 - 1,true))
  243.       {
  244.          if(_currentframe == 22)
  245.          {
  246.             gotoAndStop("lose");
  247.          }
  248.          else
  249.          {
  250.             _root.nextFrame();
  251.          }
  252.       }
  253.       if(_root.lasers.hitTest(forecast_x,forecast_y,true))
  254.       {
  255.          forecast_x = 40;
  256.          forecast_y = 40;
  257.          jumping = false;
  258.          using_jetpack = false;
  259.          has_jetpack = true;
  260.          jet_bar.jet_bar_inside._width = 109;
  261.       }
  262.       if(_root.lava.hitTest(forecast_x,forecast_y + this._height / 2 - 1,true))
  263.       {
  264.          forecast_x = 40;
  265.          forecast_y = 40;
  266.          jumping = false;
  267.          using_jetpack = false;
  268.          has_jetpack = true;
  269.          jet_bar.jet_bar_inside._width = 109;
  270.       }
  271.       while(_root.lev.hitTest(forecast_x,forecast_y + this._height / 2 - 1,true) or _root.moving.hitTest(forecast_x,forecast_y + this._height / 2 - 1,true))
  272.       {
  273.          forecast_y--;
  274.          xspeed = 0;
  275.          yspeed = 0;
  276.          jumping = false;
  277.       }
  278.       while(_root.lev.hitTest(forecast_x,forecast_y - this._height / 2,true) or _root.lava.hitTest(forecast_x,forecast_y - this._height / 2,true) or _root.moving.hitTest(forecast_x,forecast_y - this._height / 2,true))
  279.       {
  280.          forecast_y++;
  281.          yspeed = 0;
  282.       }
  283.       while(_root.lev.hitTest(forecast_x - this._width / 2 + 1,forecast_y,true))
  284.       {
  285.          forecast_x++;
  286.          xspeed = 0;
  287.       }
  288.       while(_root.lev.hitTest(forecast_x + this._width / 2,forecast_y,true))
  289.       {
  290.          forecast_x--;
  291.          xspeed = 0;
  292.       }
  293.       this._x = forecast_x;
  294.       this._y = forecast_y;
  295.       xspeed = 0;
  296.       if(climbing)
  297.       {
  298.          yspeed = 0;
  299.       }
  300.    }
  301. };
  302. rcan = true;
  303. rtimer = 0;
  304. onEnterFrame = function()
  305. {
  306.    if(rcan == false)
  307.    {
  308.       rtimer++;
  309.       if(rtimer > 30)
  310.       {
  311.          rcan = true;
  312.          rtimer = 0;
  313.       }
  314.    }
  315.    if(Key.isDown(82))
  316.    {
  317.       if(rcan == true)
  318.       {
  319.          score -= rgain;
  320.          update();
  321.       }
  322.    }
  323. };
  324. decay = false;
  325. started_game = false;
  326. attachMovie("info","info",_root.getNextHighestDepth(),{_x:250,_y:150});
  327. info._alpha = 100;
  328. info.onEnterFrame = function()
  329. {
  330.    if(decay == true)
  331.    {
  332.       this._alpha -= 2;
  333.       if(this._alpha <= 0)
  334.       {
  335.          started_game = true;
  336.          removeMovieClip(this);
  337.       }
  338.    }
  339.    if(started_game == false)
  340.    {
  341.       onMouseDown = function()
  342.       {
  343.          decay = true;
  344.       };
  345.    }
  346. };
  347.